<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>商品-入库</title>
        <meta name="renderer" content="webkit">
        <link rel="stylesheet" href="../../css/font.css"/>
        <link rel="stylesheet" href="../../css/xadmin.css"/>
        <script src="../../lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../js/xadmin.js"></script>
        <script src="../../js/vue2.7min.js"></script>
        <script src="../../js/axios.min.js"></script>
    </head>
    <body>
        <div class="layui-fluid" id="app">
            <div class="layui-row">
                <label for="L_username" class="layui-form-label">
                    <span class="x-red">*</span>可选仓库</label>

                <div class="layui-input-inline">
                    <select v-model="aimWarehouse" style="width:190px; height: 30px; border: grey">
                        <option v-for="ss in warehouseList" :value="ss">
                            {{ ss.id }} -- {{ss.name}}
                        </option>
                    </select>
                </div>

                <div class="layui-form-item">
                    <label for="L_username" class="layui-form-label">
                        <span class="x-red">*</span>入库数量</label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_username" required="" lay-verify="name" autocomplete="off"
                               class="layui-input"
                               v-model="purchaseNumber"></div>
                </div>


            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-submit="" @click="inside">入库</button>
            </div>
        </div>
        <script type="text/javascript">
            var vm = new Vue({
                el: "#app",
                data: {
                    //管理员信息
                    id: null,
                    name: "测试name",
                    level: 1,
                    password: null,
                    phone: 11111111111,
                    realName: "球球人",
                    sex: "男",
                    status: 1,
                    createTime: null,
                    updateTime: null,
                    createUser: null,
                    updateUser: null,
                    //分页属性
                    supplierId: null,
                    supplierMaster: null,
                    supplierName: "普通丘丘人",
                    supplierPhone: "12312312312",
                    supplierAddress: "提瓦特",
                    supplierMessage: "可爱丘丘人",
                    supplierEmail: "qiuqiuren@qq.com",
                    supplierStatus: null,
                    supplierCreateTime: null,
                    supplierUpdateTime: null,
                    supplierCreateUser: null,
                    supplierUpdateUser: null,
                    suppliersData: null,
                    //商品信息
                    goodsId: null,
                    goodsName: null,
                    goodsSupplierId: null,
                    goodsPrice: null,
                    goodsMessage: null,
                    goodsAddress: null,
                    //最开始查询的名下供应商数据
                    goodsSupplierData: null,
                    //名下仓库的信息
                    warehouseList: null,
                    aimWarehouse: null,
                    aimGoodsId: null,
                    purchaseNumber: null
                },
                methods: {
                    //获取名下所有的仓库信息
                    getAllWarehouseList() {
                        axios.post("../../../warehouse/getAllWarehouseList")
                            .then(function (response) {
                                console.log("打印查询的名下 warehouse 的信息");
                                //数据保存到vue全局
                                console.log(response.data)
                                vm.warehouseList = response.data;

                            }, function (err) {
                                console.log(err);

                            })
                    },
                    //获取url参数
                    url1(name) {
                        //获取上一地址中的get参数
                        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                        var r = window.location.search.substr(1).match(reg);
                        if (r != null)
                            return unescape(r[2]);
                        return null;
                    },
                    inside() {

                        //数据校验
                        if (vm.aimWarehouse === null || vm.aimWarehouse === "") {
                            layer.alert("仓库不可为空哦", {
                                icon: 6
                            })
                        } else if (vm.purchaseNumber === null || vm.purchaseNumber === "") {
                            layer.alert("采购数量不可为空哦", {
                                icon: 6
                            })
                        } else {

                            //开始axios通信
                            var jsonData = {
                                goodsId: vm.aimGoodsId,
                                warehouseId: vm.aimWarehouse.id,
                                number: vm.purchaseNumber
                            }
                            axios.post("../../../purchase/inside", jsonData)
                                .then(function (response) {
                                    //数据保存到vue全局
                                    console.log(response)
                                    if (response.data.code === 1) {
                                        layer.alert("数据新增成功", {
                                            icon: 6
                                        })
                                    }
                                }, function (err) {
                                    console.log(err);

                                })
                        }
                    }
                },
                mounted: function () {
                    //获得权限内仓库的信息,要求权限内并且启用状态。
                    this.getAllWarehouseList();
                    //获取url中商品的信息
                    this.aimGoodsId = this.url1("id");


                }
            });
        </script>
    </body>

</html>